package com.zhuss.controller.food;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zhuss.bean.bo.food.product.DetailProductBo;
import com.zhuss.bean.bo.food.product.SearchProductBo;
import com.zhuss.bean.vo.food.product.ListProductVo;
import com.zhuss.bean.vo.food.product.takeout.DetailTakeoutVo;
import com.zhuss.bean.vo.food.product.takeout.ListTakeoutVo;
import com.zhuss.common.BaseController;
import com.zhuss.common.PageVo;
import com.zhuss.common.ReadService;
import com.zhuss.enums.ProductType;
import com.zhuss.exception.WpsException;
import com.zhuss.food.product.ProductReadServiceExt;


/**
 * 外卖打包查询 controller
 * @Author zhushanshuo
   @Date 2020/03/01 16:01
 *
 */
  
 
@RestController
@RequestMapping("/takeout")
public class TakeoutReadController extends BaseController {
	
	@Autowired
	@Qualifier("productReadService")
	private ReadService<Object, Object> productReadService;
	
	@Autowired
	@Qualifier("productReadServiceExt")
	private ProductReadServiceExt productReadServiceExt;
	
	/**
	 * 详情
	 * @param bo
	 * @return
	 * @throws WpsException
	 */
	@ResponseBody
	@RequestMapping("/detail")
    public Object detail(@RequestBody DetailProductBo bo) throws WpsException {
		Object result = new DetailTakeoutVo();
		Object entity = productReadService.detail(bo);
		BeanUtils.copyProperties(entity, result);
		return result;
    }
	
	/**
	 * 列表
	 * @param bo
	 * @return
	 * @throws WpsException
	 */
	@ResponseBody
    @RequestMapping("/list")
	@SuppressWarnings("unchecked")
    public Object list(@RequestBody SearchProductBo bo) throws WpsException {
		bo.setType(ProductType.特价外卖.key());
		PageVo<ListProductVo> entity = (PageVo<ListProductVo>) productReadService.list(bo);
		PageVo<ListTakeoutVo> result = new PageVo<>();
		BeanUtils.copyProperties(entity, result);
		List<ListProductVo> items = entity.getItems();
		List<ListTakeoutVo> items2 = new ArrayList<>();
		for (ListProductVo item : items) {
			ListTakeoutVo item2 = new ListTakeoutVo();
			BeanUtils.copyProperties(item, item2);
			items2.add(item2);
		}
		result.setItems(items2);
		return result;
    }
	
}
